package com.ktjy.mapper;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class Demo2 {
    public static void main(String[] args) {
        try{
            Class cls = Class.forName("com.ktjy.pojo.Employee");
            Constructor declaredConstructor = cls.getDeclaredConstructor();
            Object obj = declaredConstructor.newInstance();
            Field empNo = cls.getDeclaredField("empNo");
            Field empName = cls.getDeclaredField("empName");
            Field empPost = cls.getDeclaredField("empPost");
            Field empSalary = cls.getDeclaredField("empSalary");
            empNo.setAccessible(true);
            empNo.set(obj,100);
            empName.setAccessible(true);
            empName.set(obj,"科泰");
            empPost.setAccessible(true);
            empPost.set(obj,"Java开发师");
            empSalary.setAccessible(true);
            empSalary.set(obj,10000);

            Method showInfo = cls.getDeclaredMethod("showInfo");

            showInfo.invoke(obj);
        }catch (Exception e){
            e.printStackTrace();
        }

    }
}
